package com.it2297.view;

import javax.swing.JPanel;
import javax.swing.JLabel;
import java.awt.Font;

import javax.swing.JOptionPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.JTextPane;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JSpinner;
import javax.swing.JComboBox;

import com.it2297.controller.WorkshopController;
import com.it2297.model.Trainer;
import com.it2297.model.Workshop;

import javax.swing.DefaultComboBoxModel;
import javax.swing.SpinnerDateModel;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Calendar;

public class DeleteWorkshopView extends JPanel {
	private final  WorkshopController controld=new WorkshopController(this);
	private final JTextField workshopidtxt;
	private final JTextField titletxt;
	private final JTextField locationtxt;
	private final JComboBox statusbox=new JComboBox();
	private final JComboBox trainerBox=new JComboBox();
	private final JTextField dstxt;
	private final JTextField detxt;
	private final JTextField descriptiontxt;
	private final JTextField capacitytxt;
	private final JTextField slottxt;
	/**

	/**
	 * Create the panel.
	 */
	public DeleteWorkshopView() {
		setLayout(null);
		
		JLabel lblDeleteWorkshop = new JLabel("Delete Workshop");
		lblDeleteWorkshop.setFont(new Font("Tahoma", Font.ITALIC, 19));
		lblDeleteWorkshop.setBounds(21, 22, 182, 31);
		add(lblDeleteWorkshop);
		
		JLabel lblNewLabel = new JLabel("Workshop ID:\r\n");
		lblNewLabel.setBounds(21, 77, 96, 14);
		add(lblNewLabel);
		
		JLabel lblNewLabel_1 = new JLabel("Title:");
		lblNewLabel_1.setBounds(21, 116, 72, 14);
		add(lblNewLabel_1);
		
		JLabel lblDateStart = new JLabel("Date Start:");
		lblDateStart.setBounds(21, 157, 96, 14);
		add(lblDateStart);
		
		JLabel lblDateEnd = new JLabel("Date End:");
		lblDateEnd.setBounds(21, 198, 72, 14);
		add(lblDateEnd);
		
		JLabel lblDescription = new JLabel("Description:");
		lblDescription.setBounds(21, 238, 72, 14);
		add(lblDescription);
		
		JLabel lblNewLabel_2 = new JLabel("Location:");
		lblNewLabel_2.setBounds(21, 294, 72, 14);
		add(lblNewLabel_2);
		
		JLabel lblCapacity = new JLabel("Capacity:");
		lblCapacity.setBounds(21, 334, 72, 14);
		add(lblCapacity);
		
		JLabel lblAvailableSlot = new JLabel("Available Slot:");
		lblAvailableSlot.setBounds(21, 372, 84, 14);
		add(lblAvailableSlot);
		
		JLabel lblStatus = new JLabel("Status:");
		lblStatus.setBounds(21, 407, 72, 14);
		add(lblStatus);
		
		workshopidtxt = new JTextField();
		workshopidtxt.setBounds(217, 74, 323, 20);
		add(workshopidtxt);
		workshopidtxt.setColumns(10);
		
		titletxt = new JTextField();
		titletxt.setBounds(217, 113, 323, 20);
		add(titletxt);
		titletxt.setColumns(10);
		
		
		
		
		locationtxt = new JTextField();
		locationtxt.setBounds(217, 291, 323, 20);
		add(locationtxt);
		locationtxt.setColumns(10);
		
		JButton btnDelete = new JButton("Delete");
		btnDelete.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				int deletechoice = JOptionPane.showConfirmDialog (null, "Are you very sure you would like to delete this workshop record?",null, JOptionPane.YES_NO_OPTION);
				if (deletechoice == JOptionPane.YES_OPTION ) {
					JOptionPane.showMessageDialog(null, "Workshop Record Deleted!");	
					controld.WorkshopStatusDel();
					statusbox.setSelectedItem("nva");
				}
				else{
					JOptionPane.showMessageDialog(null, "Cancelled, Please choose again next time");
				}
				
			}
		});
		btnDelete.setBounds(130, 492, 89, 23);
		add(btnDelete);
		
		
		JButton btnRetrieve = new JButton("Retrieve");
		btnRetrieve.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				int id=Integer.parseInt(workshopidtxt.getText());
				controld.getWorkshopDetail(id);
				workshopidtxt.setEditable(false);
				if(workshopidtxt.getText().isEmpty()){
					JOptionPane.showMessageDialog(null,"Please Enter The W");
					workshopidtxt.setText("");
					workshopidtxt.setEditable(true);
					titletxt.setText("");
					locationtxt.setText("");
					
					
				}
			
				
			}
		});
		btnRetrieve.setBounds(341, 492, 89, 23);
		add(btnRetrieve);
		
		
		statusbox.setModel(new DefaultComboBoxModel(new String[] {"Ava", "Nva"}));
		statusbox.setBounds(217, 404, 160, 20);
		add(statusbox);
		
		JLabel lblTrainerNric = new JLabel("Trainer NRIC:");
		lblTrainerNric.setBounds(21, 447, 107, 14);
		add(lblTrainerNric);
		
		
		dstxt = new JTextField();
		dstxt.setBounds(217, 154, 323, 20);
		add(dstxt);
		dstxt.setColumns(10);
		
		detxt = new JTextField();
		detxt.setBounds(217, 195, 323, 20);
		add(detxt);
		detxt.setColumns(10);
		
		descriptiontxt = new JTextField();
		descriptiontxt.setBounds(217, 235, 323, 38);
		add(descriptiontxt);
		descriptiontxt.setColumns(10);
		
		capacitytxt = new JTextField();
		capacitytxt.setBounds(217, 331, 323, 20);
		add(capacitytxt);
		capacitytxt.setColumns(10);
		
		slottxt = new JTextField();
		slottxt.setBounds(217, 369, 323, 20);
		add(slottxt);
		slottxt.setColumns(10);
		
		JButton btnRefresh = new JButton("Refresh");
		btnRefresh.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				workshopidtxt.setEditable(true);
				workshopidtxt.setText("");
				titletxt.setText("");
				locationtxt.setText("");
				descriptiontxt.setText("");
				dstxt.setText("");
				detxt.setText("");
				capacitytxt.setText("");
				slottxt.setText("");
				statusbox.removeAllItems();
				
				
				
			}
		});
		btnRefresh.setBounds(231, 492, 89, 23);
		add(btnRefresh);
		
		JComboBox trainerBox=new JComboBox();
		trainerBox.setBounds(217, 444, 138, 20);
		for(int i=0; i< Trainer.getMultiple().size();i++){
			trainerBox.addItem(Trainer.getMultiple().get(i).getNric());
			add(trainerBox);
			}
		

	}
	public String getStatus() {
		return statusbox.getSelectedItem().toString();
	}
	public void setStatus(String status){
		statusbox.setSelectedItem(status);
	}

	public int getWorkshopId() {
		return Integer.parseInt(workshopidtxt.getText());
	}
		
	
	public String getTitle(){
		return titletxt.getText();
	}
	public void setTitle(String title){
		titletxt.setText(title);
	}
	public String getlocation() {
		return locationtxt.getText();
	}
	public void setlocation(String location){
		locationtxt.setText(location);
	}
	public int getCapacity(){
		return Integer.parseInt(capacitytxt.getText());
	}
	public void setCapacity(int totalcapacity){
		capacitytxt.setText(Integer.toString(totalcapacity));
	}
	public int getAvailableSlot(){
		return Integer.parseInt(slottxt.getText());
	}
	public void setAvailableSlot(int availableslot){
		slottxt.setText(Integer.toString(availableslot));
	}
	
	public String getDescription(){
		return descriptiontxt.getText();
	}
	public void setDescription(String description){
		descriptiontxt.setText(description);
	}
	public void setStartDate(Date dateStart){
		 DateFormat df = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
		 String reportDate = df.format(dateStart);
		 dstxt.setText(reportDate);
	}
	
	
	public Date getStartDate(){
		DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); 
		Date date = null;
		try {
		  date=	(Date)formatter.parse(dstxt.getText());
		} catch (Exception e) {
			
			e.printStackTrace();
		}
		System.out.println(date);
		 return date;
		
		
		
		
	}
		public Date getEndDate(){
			DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); 
			Date date=null;
			try {
				date = (Date)formatter.parse(detxt.getText());
			} catch (Exception e) {
				
				e.printStackTrace();
			}
			System.out.println(date);
			 return date;
		
		}
		public void setEndDate(Date dateEnd){
			DateFormat df = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
			 String reportDate = df.format(dateEnd);
			 detxt.setText(reportDate);
		}
	

		public String getNRIC(){
			return (String) trainerBox.getSelectedItem();
		}
		public void setNRIC(String trainernric){
			trainerBox.setSelectedItem(trainernric);
		}
}
